home *** CD-ROM | disk | FTP | other *** search
- /*
- * SFtoSpr - Star Fighter 3000 graphics converter
- * Iconbar menu
- * Copyright (C) 2000 Chris Bazley
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public Licence as published by
- * the Free Software Foundation; either version 2 of the Licence, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public Licence
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /* ANSI library files */
- #include <stdlib.h>
-
- /* RISC OS library files */
- #include "kernel.h"
- #include "toolbox.h"
- #include "event.h"
- #include "menu.h"
- #include "saveas.h"
-
- /* My library files */
- #include "err.h"
- #include "Macros.h"
- #include "Loader.h"
- #include "ViewsMenu.h"
-
- /* Local headers */
- #include "SFmenu.h"
- #include "PreQuit.h"
- #include "Main.h"
-
- /* Item IDs */
- #define MENU_HELP 0
- #define MENU_QUIT 2
- #define MENU_VIEWS 3
- #define MENU_MULTI 4
-
- /* ----------------------------------------------------------------------- */
- /* Function prototypes */
-
- static ToolboxEventHandler _Menu_selecthandler, _Menu_showhandler;
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- void Menu_initialise(ObjectId id)
- {
- /* Listen for selections */
- EF(event_register_toolbox_handler(id, Menu_Selection, _Menu_selecthandler, 0));
- EF(event_register_toolbox_handler(id, Menu_AboutToBeShown, _Menu_showhandler, 0));
- EF(ViewsMenu_parentcreated(id, MENU_VIEWS));
- }
-
-
- /* ----------------------------------------------------------------------- */
- /* Private functions */
-
- static int _Menu_showhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- RE(menu_set_tick(0, id_block->self_id, MENU_MULTI, (int)multi_saveboxes));
-
- return 0; /* pass event on (to ViewsMenu) */
- }
-
- /* ----------------------------------------------------------------------- */
-
- static int _Menu_selecthandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- /* Handle click on icon bar menu */
- ObjectId editingwindow;
- ObjectClass object_class;
-
- switch(id_block->self_component) {
- case MENU_MULTI:
- /* Update menu entry tick (doesn't do it automatically!) */
- multi_saveboxes = !multi_saveboxes;
- RE(menu_set_tick(0, id_block->self_id, MENU_MULTI, (int)multi_saveboxes));
-
- if(!multi_saveboxes) {
- /* Remove all pre-existing saveboxes */
- editingwindow = ViewMenu_getfirst();
- while(editingwindow != NULL_ObjectId) {
- RE(toolbox_get_object_class(0, editingwindow, &object_class));
- if(object_class == SaveAs_ObjectClass && editingwindow != last_savebox)
- RE(toolbox_delete_object(0, editingwindow));
-
- editingwindow = ViewMenu_getnext(editingwindow);
- }
- }
- return 1; /* claim event */
-
- case MENU_HELP:
- /* load help */
- if(_kernel_oscli("Filer_Run SFtoSprRes:Help") == _kernel_ERROR)
- err_check_rep(_kernel_last_oserror());
- return 1; /* claim event */
-
- case MENU_QUIT:
- /* quit program */
- if(TRY_QUIT(0))
- exit(EXIT_SUCCESS); /* safe to quit */
- return 1; /* claim event */
- }
- return 0; /* not handled */
- }
-